//
//  SKU_DetailTakeinUserInfoV_View_WX.m
//  ZITHER
//
//  Created by weixin on 2019/2/25.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "SKU_DetailTakeinUserInfoV_View_WX.h"

@implementation SKU_DetailTakeinUserInfoV_View_WX

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
        [self setMasonry];
    }
    return self;
}
-(void)setModel:(AcceptPriceListModel *)model{
    _model = model;
    [self.Map sd_setImageWithURL:[NSURL URLWithString:[NSString getMapImageView:model.latitude markers:model.longitude]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        //        NSLog(@"map ==== %@ %@ ")
        self.Map.image = image.grayImage;//图片变灰
        
    }];

    [self.userIcon sd_setImage:model.bizPortrait];
    self.userName.text = model.bizNickName;
    self.city.text = [NSString stringWithFormat:@"%@%@%@%@",model.province,model.city,model.area,model.bizAddr];

    self.phone.text = model.bizPhone;
    self.Wechat.text = model.bizWechat;
    if (self.Wechat.text.length == 0) {
        self.Wechat.hidden = YES;
        self.WechatTitle.hidden = YES;
    }else{
        self.Wechat.hidden = NO;
        self.WechatTitle.hidden = NO;
    }
}

-(void)setUI{

    [self addSubview:self.Map];//价格
    [self addSubview:self.userIcon];//价格
    [self addSubview:self.userName];//价格
    [self addSubview:self.city];//价格
    [self addSubview:self.phone];
    [self addSubview:self.Wechat];
    [self addSubview:self.phoneTitle];
    [self addSubview:self. WechatTitle];
}


/**
 
 Map;//价格
 userIcuserNameon;//价格
 userName;//价格
 city;//价格
 phone;
 Wechat;
 
 */


-(void)setMasonry{
    
    [self.Map mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(90);
        make.top.left.right.equalTo(self).offset(0);
    }];

    [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.Map.mas_bottom).offset(-15);
        make.left.equalTo(self).offset(17);
        make.height.width.mas_equalTo(60);
    }];

    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.Map.mas_bottom).offset(11);
        make.left.equalTo(self.userIcon.mas_right).offset(6);
        make.height.mas_equalTo(16);
    }];

    [self.city mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userName.mas_bottom).offset(2);
        make.left.equalTo(self.userIcon.mas_right).offset(6);
        make.height.mas_equalTo(13);
    }];


    [self.phoneTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.phone.mas_bottom).offset(5);
        make.left.equalTo(self.userIcon.mas_right).offset(6);
        make.height.mas_equalTo(15);
    }];

    [self.WechatTitle mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.phone.mas_bottom).offset(5);
        make.left.equalTo(self.Wechat).offset(0);
        make.height.mas_equalTo(15);
    }];

    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.city.mas_bottom).offset(16);
        make.left.equalTo(self.userIcon.mas_right).offset(6);
        make.height.mas_equalTo(15);
    }];
    
    [self.Wechat mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.city.mas_bottom).offset(16);
        make.left.equalTo(self.phone.mas_right).offset(30);
        make.height.mas_equalTo(15);
    }];

}

- (BaseImageV *)Map{
    if (!_Map) {
        _Map = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 90, kScreenW) contentMode:2];
//        _Map.backgroundColor = [UIColor greenColor];

    }
    return _Map;
}


- (BaseImageV *)userIcon{
    if (!_userIcon) {
        _userIcon = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 90, kScreenW) contentMode:2];
        [_userIcon setCornerRadiusWithRadius:30 isMasks:YES];
        _userIcon.backgroundColor = [UIColor clearColor];

//        _userIcon.backgroundColor = [UIColor redColor];
    }
    return _userIcon;
}

- (BaseLab *)userName{
    if (!_userName) {
        _userName = [BaseLab initCustomLab:@"商家名称" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFang-SC-Regular" size:15]];
        _userName.numberOfLines = 1;
        _userName.backgroundColor = [UIColor clearColor];

    }
    return _userName;
}

- (BaseLab *)city{
    if (!_city) {
        _city = [BaseLab initCustomLab:@"商家地址" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFang-SC-Regular" size:12]];
        _city.backgroundColor = [UIColor clearColor];

        _city.numberOfLines = 1;
    }
    return _city;
}

- (BaseLab *)phone{
    if (!_phone) {
        _phone = [BaseLab initCustomLab:@"139204123123" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFangSC-Semibold" size:14]];
        _phone.numberOfLines = 1;
        _phone.backgroundColor = [UIColor clearColor];
        [[_phone addTag]subscribeNext:^(id  _Nullable x) {
            
            NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"电话号码:%@",self.phone.text];
            
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            }];
            UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.phone.text]];
                [[UIApplication sharedApplication] openURL:url];
            }];
            // Add the actions.
            
            [alertController addAction:cancelAction];
            
            [alertController addAction:otherAction];
            
            [self.getNav presentViewController:alertController animated:YES completion:nil];
        }];

    }
    return _phone;
}

- (BaseLab *)Wechat{
    if (!_Wechat) {
        _Wechat = [BaseLab initCustomLab:@"139204123123" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFangSC-Semibold" size:14]];
        _Wechat.numberOfLines = 1;
        _Wechat.backgroundColor = [UIColor clearColor];
        [[_Wechat addTag]subscribeNext:^(id  _Nullable x) {
            UIPasteboard *pab = [UIPasteboard generalPasteboard];
            NSString *string = self.Wechat.text;
            [pab setString:string];
            if (pab == nil) {
                [Tools showTips:@"复制失败"];
                
            }else{
                [Tools showTips:@"已复制"];
            }
            
            
            NSURL *url = [NSURL URLWithString:@"weixin://"];
            
            [[UIApplication sharedApplication] openURL:url];
            
        }];

    }
    return _Wechat;
}

- (BaseLab *)phoneTitle{
    if (!_phoneTitle) {
        _phoneTitle = [BaseLab initCustomLab:@"手机" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFang-SC-Regular" size:12]];
        _phoneTitle.numberOfLines = 1;
        _phoneTitle.backgroundColor = [UIColor clearColor];
    }
    return _phoneTitle;
}

- (BaseLab *)WechatTitle{
    if (!_WechatTitle) {
        _WechatTitle = [BaseLab initCustomLab:@"微信" color:HexColor(0x333333) font:[UIFont fontWithName:@"PingFang-SC-Regular" size:12]];
        _WechatTitle.numberOfLines = 1;
        _WechatTitle.backgroundColor = [UIColor clearColor];
    }
    return _WechatTitle;
}





@end
